import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

//静态路由配置
void main() => runApp(const MyApp3());

//定义根目录Widget
class MyApp3 extends StatelessWidget {
  const MyApp3({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      localizationsDelegates: const [
        //初始化默认的 Material 组件本地化
        GlobalMaterialLocalizations.delegate,
        //初始化默认的 通用 Widget 组件本地化
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      //当前区域，如果为null则使用系统区域一般用于语言切换
      //传入两个参数，语言代码，国家代码
      //这里配制为中国
      locale: const Locale('zh', 'CN'),
      //定义当前应用程序所支持的语言环境
      supportedLocales: const [
        Locale('en', 'US'), // English 英文
        Locale('zh', 'CN'), // 中文
      ],
      routes: {
        //默认页面
        "/": (BuildContext context) => const Exam306HomePage(),
      },
    );
  }
}

///代码清单 3-6 登录页面Demo
///代码路径 lib/code3/code305_Wrap.dart
class Exam306HomePage extends StatefulWidget {
  const Exam306HomePage({Key? key}) : super(key: key);
  @override
  State<Exam306HomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<Exam306HomePage> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SizedBox(
        width: double.infinity,
        height: double.infinity,
        child: Stack(
          children: [
            //第一层 背景图片
            buildFunction1(),
            //第二层 高斯模糊
            buildFunction2(),
            //第三层 登录输入层
            buildFunction3(),
          ],
        ),
      ),
    );
  }

  buildFunction1() {
    return Positioned.fill(
      child: Image.asset(
        "assets/images/loginbg.png",
        fit: BoxFit.fill,
      ),
    );
  }

  buildFunction2() {
    return Positioned.fill(
      child: BackdropFilter(
        filter: ImageFilter.blur(sigmaX: 3, sigmaY: 3),
        child: Container(
          color: Colors.white.withOpacity(0.4),
        ),
      ),
    );
  }

  ///用户名使用
  late final TextEditingController _nameController = TextEditingController();
  ///密码输入框使用
  late final TextEditingController _passwordController =
  TextEditingController();

  buildFunction3() {
    return Positioned.fill(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          SizedBox(
            width: 300,
            child: TextField(
              controller: _nameController,
              decoration: const InputDecoration(
                hintText: "请输入用户名",
                border: OutlineInputBorder(
                  borderRadius: BorderRadius.all(Radius.circular(33)),
                  borderSide: BorderSide(
                    color: Colors.grey,
                  ),
                ),
              ),
            ),
          ),
          const SizedBox(height: 20),
          SizedBox(
            width: 300,
            child: TextField(
              controller: _passwordController,
              decoration: const InputDecoration(
                hintText: "请输入密码",
                border: OutlineInputBorder(
                  borderRadius: BorderRadius.all(Radius.circular(33)),
                  borderSide: BorderSide(
                    color: Colors.grey,
                  ),
                ),
              ),
            ),
          ),
          const SizedBox(height: 40),
          SizedBox(
            width: 300,
            height: 48,
            child: ClipRRect(
              borderRadius: const BorderRadius.all(Radius.circular(33)),
              child: ElevatedButton(
                onPressed: () {
                  String name = _nameController.text;
                  String password = _passwordController.text;

                  print("获取到的内容是 $name  $password");
                },
                child: const Text("登录"),
              ),
            ),
          )
        ],
      ),
    );
  }
}
